import request from '@/utils/request'
import { apiVersion } from '@/config'

/**
 * 列表
 * @param {} data
 */
export function getTasks(data) {
  return request({
    url: `/admin/${apiVersion}/task`,
    method: 'get',
    data
  })
}

/**
 * 全部
 * @param {} data
 */
export function getAllTasks(data) {
  return request({
    url: `/admin/${apiVersion}/task/all`,
    method: 'get',
    data
  })
}
/**
 * 添加
 * @param {} data
 */
export function addTask(data) {
  return request({
    url: `/admin/${apiVersion}/task`,
    method: 'post',
    data: data
  })
}
/**
 * 删除
 * @param {} data
 */
export function delTask(data) {
  return request({
    url: `/admin/${apiVersion}/task/${data.id}`,
    method: 'delete',
    data
  })
}
/**
 * 更新
 * @param {} data
 */
export function putTask(data) {
  return request({
    url: `/admin/${apiVersion}/task`,
    method: 'put',
    data: data
  })
}
/**
 * 取得详情
 * @param {*} data
 */
export function getTaskDetail(data) {
  return request({
    url: `/admin/${apiVersion}/task/${data.id}`,
    noLoadding: true,
    method: 'get',
  })
}

/**
 * 版本列表
 * @param {} data
 */
export function getTaskVersions(data) {
  return request({
    url: `/admin/${apiVersion}/taskVersion`,
    method: 'get',
    data
  })
}
// 根据来源查询
export function getTaskBySource(data) {
  return request({
    url: `/admin/${apiVersion}/task/bySource`,
    method: 'get',
    data
  })
}
/**
 * 获取监控分页列表(非停止状态)
 * @param {} data
 */
export function getTaskVersionsMonitor(data) {
  return request({
    url: `/admin/${apiVersion}/taskVersion/monitor`,
    method: 'get',
    data
  })
}
/**
 * 版本添加
 * @param {} data
 */
export function addTaskVersion(data) {
  return request({
    url: `/admin/${apiVersion}/taskVersion`,
    method: 'post',
    data: data
  })
}
/**
 * 版本删除
 * @param {} data
 */
export function delTaskVersion(data) {
  return request({
    url: `/admin/${apiVersion}/taskVersion/${data.id}`,
    method: 'delete',
    data
  })
}
/**
 * 版本更新
 * @param {} data
 */
export function putTaskVersion(data) {
  return request({
    url: `/admin/${apiVersion}/taskVersion`,
    method: 'put',
    data: data
  })
}
/**
 * 取取版本详情
 * @param {*} data
 */
export function getTaskVersionDetail(data) {
  return request({
    url: `/admin/${apiVersion}/taskVersion/${data.id}`,
    noLoadding: true,
    method: 'get',
  })
}

export function getAllTaskVersions(data) {
  return request({
    url: `/admin/${apiVersion}/taskVersion/all`,
    noLoadding: true,
    method: 'get',
    data: data
  })
}
/**
 * 获取podname
 * @param {*} data
 */
export function getTaskVersionPodName(data) {
  return request({
    url: `/admin/${apiVersion}/taskVersion/${data.id}/podName`,
    noLoadding: true,
    method: 'get',
  })
}

/**
 * 启动
 * @param {} data
 */
export function startTaskVersion(data) {
  return request({
    url: `/admin/${apiVersion}/taskVersion/${data.id}/start`,
    method: 'put',
    data
  })
}
/**
 * 停止
 * @param {} data
 */
export function stopTaskVersion(data) {
  return request({
    url: `/admin/${apiVersion}/taskVersion/${data.id}/stop`,
    method: 'put',
    data
  })
}
/**
 * 获取指标或图示数据详情
 * @param {*} data
 */
export function metricData(data) {
  return request({
    url: `/admin/${apiVersion}/taskVersion/${data.id}/metric/data`,
    noLoadding: true,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    method: 'get',
    data
  })
}
/**
 * 获取指标或图示名称
 * @param {*} data
 */
export function metricKeys(data) {
  return request({
    url: `/admin/${apiVersion}/taskVersion/${data.id}/metric/keys`,
    noLoadding: true,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    method: 'get',
    data
  })
}

/**
 * 创建pvc
 * @param {} data
 */
export function createPvc(data) {
  return request({
    url: `/admin/${apiVersion}/taskVersion/${data.id}/createPvc`,
    method: 'put',
    data
  })
}

/**
 * 删除pvc
 * @param {} data
 */
export function deletePvc(data) {
  return request({
    url: `/admin/${apiVersion}/taskVersion/${data.id}/deletePvc`,
    method: 'put',
    data
  })
}
